<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title th:text="${gameType.gname} + ' - 账号列表'"></title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" th:href="@{/page/css/swiper.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/page/css/index.css}">
    <link rel="stylesheet" type="text/css" th:href="@{/page/css/page.css}">
    <link th:href="@{/css/font-awesome.min.css?v=4.7.1}" rel="stylesheet"/>
    <th:block th:include="include :: header('弹层组件')" />
    <style>
        /* 设置滚动条的样式 */
        ::-webkit-scrollbar {
            width:12px;
        }
        /* 滚动槽 */
        ::-webkit-scrollbar-track {
            -webkit-box-shadow:inset006pxrgba(0,0,0,0.3);
            border-radius:10px;
        }
        /* 滚动条滑块 */
        ::-webkit-scrollbar-thumb {
            border-radius:10px;
            background:rgba(0,0,0,0.1);
            -webkit-box-shadow:inset006pxrgba(0,0,0,0.5);
        }
        ::-webkit-scrollbar-thumb:window-inactive {
            background:rgba(255,0,0,0.4);
        }
        .fa-angle-down:hover,.fa-angle-up:hover{
            cursor: pointer;
        }
         .copybtn{
             display: inline-block;
             padding: 2px 5px;
             float:right;
             background: #1a1a1a;
             color:#Fff;
             margin-left: 10px;
             border-radius: 5px;
             cursor: pointer;
         }
        .layui-layer-min{
            display: none;
        }

        .layui-layer-content{
            overflow-y: auto; !important;
        }
    </style>
    <script th:src="@{/page/js/jq.js}"></script>
</head>
<body>
<div class="w100 bgr">
    <div class="header">
        <div class="logo">
            <h1 th:text="${gameType.gname}"></h1>
        </div>
        <div class="search">
            <form action="" method="">
                <input type="search" id="input-key" placeholder="请输入关键字进行查找.."/>
                <button id="key-search-bth">搜索</button>
            </form>
        </div>
        <div class="clear"></div>
    </div>
</div>
<div class="w100 bgy non">
    <div class="nav"><a href="/">首页</a></div>
</div>
<div class="main">
    <div class="main_top">
        <span style="margin: 0 6px;color: white" id="price-select">点击筛选价格</span>
        <span style="color:white;line-height: 40px;margin-left: 10px;" onclick="toggle()">
            价格高低
            <i class="fa fa-angle-down"></i>
            <i class="fa fa-angle-up" style="display: none"></i>
        </span>
        <div class="showjump bignon">条件筛选</div>
        <div class="jumpbox">
            <form>
                <div class="bignon">
                    <b class="btit">条件选项</b>
                </div>
                <div th:utext="${htmlText}"></div>
                <div class="bignon">
                    <button id="search-btn">确认</button>
                    <button class="cancel">取消</button>
                </div>
            </form>
        </div>

    </div>
    <div class="main_cont">
        <div id="pro-list"></div>
        <div class="clear"></div>
        <div style="text-align: center;margin:10px auto;">
            <div id="pager" class="pager clearfix"></div>
        </div>
    </div>
</div>
<div class="copyright">
    <p><a href="javascript:void(0)"  th:text="${gameType.gname}"></a></p>
</div>
<div class="tabbar">
    <div class="tabbox">
        <a href="/"><i style="font-size: 24px" class="fa fa-home"></i><p>首页</p></a>
    </div>
    <!--<div class="tabbox">
        <a href="/wx"><i style="font-size: 24px" class="fa fa-user"></i><p>店长微信</p></a>
    </div>-->
    <div class="tabbox">
        <a href="/lc"><i style="font-size: 24px" class="fa fa-exchange"></i><p>交易流程</p></a>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:src="@{/page/js/jquery.z-pager.js}" type="text/javascript" charset="utf-8"></script>
<script th:src="@{/page/js/clipboard.min.js}"></script>
<script th:inline="javascript">
    var  accounts = [];
    var  results = [];
    $.post("/listData",{typeId:[[${gameType.id}]]},function(result){
            if(result.code == 0){
                accounts = result.data;
                results = result.data;
                maxPage = Math.ceil(result.data/pageData);
                $("#pager").zPager({
                    totalData: results.length,
                    pageData: pageData,
                    pageStep: 6, //当前可见最多页码个数
                    minPage: 5, //最小页码数，页码小于此数值则不显示上下分页按钮
                    ajaxSetData: false,
                    btnShow: false
                });
            }else{
                alert("数据获取失败!");
            }
    });
    //鼠标复制代码
    var clipboard = new ClipboardJS('.copybtn', {
        function (e) {
            /*console.log(e.trigger)
            return '11'*/;
        },
    });

    clipboard.on('success', function (e) {
        alert("复制成功!");
        console.log(e);
    });

    clipboard.on('error', function (e) {
        console.log(e);
    });

    $("#price-select").click(function(){
        var options = {
            title:  '价格筛选',
            width: '400',
            height: '600',
            maxmin: false,
            btnAlign: 'l',
            url: "/select",
            btn: ['确定', '关闭'],
            callBack: callback
        };
        $.modal.openOptions(options);
    })
    //回调函数
    function callback(index, layero) {
        var body = $.modal.getChildFrame(index);
        var price = body.find("#price").val();
        results = [];
        console.log(price)
        if(price.indexOf("-") === -1){
            //大于一万
            console.log("大于一万")
            accounts.forEach(item => {
                if(item.price >=  price){
                    results.push(item);
                }
            });
        }else{
            var prices = price.split("-");
            var startPrice = prices[0];
            var endPrice = prices[1];
            console.log("区间搜素",startPrice,endPrice);
            accounts.forEach(item => {
                if(item.price >=  startPrice && item.price <=  endPrice ){
                    results.push(item);
                }
            });
        }
        currentPage(1);
        $("#pager").zPager({
            totalData: results.length,
            pageData: pageData,
            pageStep: 6, //当前可见最多页码个数
            minPage: 5, //最小页码数，页码小于此数值则不显示上下分页按钮
            ajaxSetData: false,
            btnShow: false
        });
        $.modal.close(index);
    }



    //数组价格排序功能
    function  sortData1(a,b) {
       return b.price - a.price;
    }
    function  sortData2(a,b) {
       return a.price - b.price;
    }

    function toggle() {
        var sort = false;
        if($(".fa-angle-down").css('display')  === 'inline-block'){
           $(".fa-angle-down").css('display','none');
           $(".fa-angle-up").css('display','inline-block');
        }else{
            sort = true;
            $(".fa-angle-down").css('display','inline-block');
            $(".fa-angle-up").css('display','none');
        }
        if(sort){
            results.sort(sortData2)
        }else{
            results.sort(sortData1)
        }
        currentPage(1);
    }
    var pageData = 5;
    var pageStepnum
    if($(window).width() <  330){
        pageStepnum = 4;
        pageData = 6;
    }else{
        pageStepnum = 6
    }
    $("#gotop").click(function() {
        $('body,html').animate({
                scrollTop: 0
            },
            500);
        return false;
    });
    $(".showjump").click(function() {
        $('.jumpbox').animate({
                'right':'0px'
            },
            500);
        return false;
    });
    $(".cancel").click(function() {
        $('.jumpbox').animate({
                'right':'-100vw'
            },
            500);
        return false;
    });
    $("#key-search-bth").click(function (e) {
        e.preventDefault();
        var key = $('#input-key').val();
        results = [];
        if(key == ''){
            alert('请输入关键字!')
            accounts.forEach(item => {
                results.push(item)
            });
        }else{
            accounts.forEach(item => {
                if (item.title.indexOf(key) !== -1) {
                    results.push(item)
                }
            });
        }
        currentPage(1);
        $("#pager").zPager({
            totalData: results.length,
            pageData: pageData,
            pageStep: 6, //当前可见最多页码个数
            minPage: 5, //最小页码数，页码小于此数值则不显示上下分页按钮
            ajaxSetData: false,
            btnShow: false
        });
        $(".cancel").trigger('click');
    });
    //搜索执行
    $("#search-btn").click(function(event){
        event.preventDefault();
        var keywords = [];
        $('input[type="radio"]:checked').each(function() {
            keywords.push($(this).val());
        });
        $('input[type="checkbox"]:checked').each(function() {
            keywords.push($(this).val());
        });
        //console.log(keywords)
        results = [];
        accounts.forEach(item => {
            var parg3 = item.searchParam ? item.searchParam.split(',') : ''
            if (keywords.every(key => parg3.indexOf(key) !== -1)) {
                results.push(item)
            }
        });
        //console.log(results)
        currentPage(1);
        $("#pager").zPager({
            totalData: results.length,
            pageData: pageData,
            pageStep: 6, //当前可见最多页码个数
            minPage: 5, //最小页码数，页码小于此数值则不显示上下分页按钮
            ajaxSetData: false,
            btnShow: false
        });
        $(".cancel").trigger('click');
    });
    function currentPage(currentPage){
        var start = (currentPage - 1) *  pageData;
        var end = currentPage  *  pageData;
        var txtHtml = '';
        for(var i= start;i<end;i++){
            if(i>=results.length) break;
            txtHtml += '<div class="pro">';
            txtHtml += '<div>';
            ///detail/'+results[i].id+'.html
                txtHtml += '<p class="tit"><a href="javascript:detail('+results[i].id+')" style="text-decoration: none">'+results[i].title+'</a></p>';
                txtHtml += '<p><span class="price">￥'+results[i].price
                    +'</span><span class="copybtn" data-clipboard-action="copy" data-clipboard-target=".num_no'+i
                    +'">一键复制</span><span class="num" style="color: red;">编号:<span style="margin-right: 10px;color: red;"> '+results[i].accountNo
                    + '</span><span style="color: red;">账号:</span><span style="color: red;" class="num_no'+i+'">'+ results[i].gameNo + '</span></span></p>';
            txtHtml += '</div>';
            if(results[i].imgs){
                txtHtml += '<a href="javascript:detail('+results[i].id+')">'+'<img style="width: 100%" src="'+results[i].imgs.split(",")[0]+'"/></a>';
            }else{
                txtHtml += ' <img src="/page/img/2.jpg"/>';
            }
            txtHtml += '</div>';
        }
        if(txtHtml == ''){
            $("#pager").hide();
        }else{
            $("#pager").show();
        }
        $("#pro-list").html(txtHtml);
        document.body.scrollTop = document.documentElement.scrollTop = 0;
    }

    let index;
    function detail(id){
          index = layer.open({
            type: 2,
            content: "/detail/" + id + ".html",
            title: false,
            area: ['100%','100%'],
            maxmin: false,
            //btn: ['关闭'],
            closeBtn: 0
            /*yes: function(){
                console.log(Window.name)
                var index1 =  parent.layer.getFrameIndex(Window.name);
                console.log(index1)
                parent.layer.close(index1);
            }*/
        });
        //layer.full(index);
    }

    function closeT(){
        layer.close(index);
    }
</script>
</body>
</html>